package hello;


public class Artifact {
	private String group;
	private String artifact;
	private Version version;

	public Artifact(String group, String artifact, Version version) {
		//TODO check if the business if this assertion is still important
        //assert group!=null && artifact!=null && version!=null : "group, artifact and version cannot be null";
        assert group!=null && artifact!=null : "group and artifact cannot be null";
		this.group = group;
		this.artifact = artifact;
		this.version = version;
	}
	
	

	public String getGroup() {
		return group;
	}

	public String getArtifact() {
		return artifact;
	}

	public Version getVersion() {
		return version;
	}

	public String getName() {
        return new StringBuilder()
                .append(getGroup()).append(':')
                .append(getArtifact())
                .toString();
    }

    @Override
    public String toString() {
        return new StringBuilder()
                .append(getGroup()).append(':')
                .append(getArtifact()).append(':')
                .append(getVersion())
                .toString();
    }

    @Override
    public final boolean equals(final Object obj) {
        if ( this==obj ) {
            return true;
        } else if ( !(obj instanceof Artifact) ) {
            return false;
        } else {
            final Artifact that = (Artifact) obj;
            return  this.getGroup().equals(that.getGroup()) &&
                    this.getArtifact().equals(that.getArtifact()) &&
                    this.getVersion().equals(that.getVersion());
        }
    }

    @Override
    public final int hashCode() {
        final int hash = 11;
        return  getGroup().hashCode() * hash +
                getArtifact().hashCode() * hash +
                ((getVersion() == null) ? 0 : getVersion().hashCode()) * hash;
    }
}
